package operation;

import books.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    public int search(BookList bookList) {
        System.out.println("请输入你要归还的图书名");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine() ;
        int len = bookList.getBookSize() ;
        for(int i = 0 ; i < len ; i ++){
            if(bookList.books[i].getName().equals(name)) {
                return i;
            }
        }
        return -1 ;
    }

    @Override
    public void work(BookList bookList) {
      int tmp = search(bookList) ;
      if(tmp == -1 ){
          System.out.println("这本书不是图书馆的");
      }else{
         bookList.books[tmp].setIsBorrow(false);
          System.out.println("这本书已归还");
      }


    }
}